#ifndef _Texture_H_
#define _Texture_H_

#pragma once
#include "Material.h"
#include "IntersectResult.h"

class Texture : public Material, protected enable_shared_from_this<Texture> {
public:
	enum Mapping {
		UV, Position, Sky
	};
protected:
	Mapping mapping = UV;
	Vector3 scale = Vector3(1.0, 1.0, 1.0), offset;

public:
	Texture() {}
	virtual ~Texture() {}

	shared_ptr<Texture> setMapping(Mapping mapping) {
		this->mapping = mapping;
		return shared_from_this();
	}
	const Mapping getMapping() const {
		return mapping;
	}

	shared_ptr<Texture> setScale(const Vector3 &scale) {
		this->scale = scale;
		return shared_from_this();
	}
	Vector3 getScale() const {
		return scale;
	}

	shared_ptr<Texture> setOffset(const Vector3 &offset) {
		this->offset = offset;
		return shared_from_this();
	}
	Vector3 getOffset() const {
		return offset;
	}

	virtual Color shade(const Scene *scene, const Ray &ray, const IntersectResult &intersect, const TraceState & traceState) const {
		switch (mapping) {
		case Texture::UV:
			return value(intersect.uv.x * scale.x + offset.x, intersect.uv.y * scale.y + offset.y, offset.z);
		case Texture::Position:
			return value(intersect.position.x * scale.x + offset.x,intersect.position.y * scale.y + offset.y,intersect.position.z * scale.z + offset.z);
		default:
			return Colors::Black;
		}
	}

	virtual Color value(Double u, Double v, Double w) const {
		return Colors::Black;
	}
};

#endif // _Material_H_